package com.stadyhelper.contreller;

import com.stadyhelper.Utils.SparkManagerUtil;
import com.stadyhelper.pojo.PageBean;
import com.stadyhelper.pojo.Result;
import com.stadyhelper.pojo.Score;
import com.stadyhelper.service.ScoreService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Validated
@RestController
@RequestMapping("/score")
public class ScoreController {
    @Autowired
    private ScoreService scoreService;
    @Resource
    private SparkManagerUtil sparkManagerUtil;
    //添加成绩接口
    @PostMapping
    public Result<Score> addScore(@RequestBody @Validated Score score) {
        scoreService.addScore(score);
        return Result.success(score);
    }
    //删除成绩接口
    @DeleteMapping
    public Result deleteScore(@RequestParam Integer id) {
        scoreService.deleteScore(id);
        return Result.success();
    }
    //修改成绩接口
    @PutMapping
    public Result updateScore(@RequestBody @Validated Score score) {
        scoreService.updateScore(score);
        return Result.success();
    }
    //列出成绩接口
    @GetMapping
    public Result<PageBean<Score>> listScore(Integer pageNum, Integer pageSize,
                                             @RequestParam(required = false) String name) {
    PageBean<Score> pageBean = scoreService.listScore(pageNum,pageSize,name);
    return Result.success(pageBean);
    }
    //成绩分析接口
    @GetMapping("/analysis")
    public Result analysis() {
        String s=scoreService.selectNewScore();
        String analysis= sparkManagerUtil.sendMesToAIUseXingHuo(s);
        log.info(analysis);
        return Result.success(analysis);
    }
    //获取图表数据接口
    @GetMapping("/model")
    public Result<List<Score>> modelScore(@RequestParam Integer modelNum) {
        List<Score> s= scoreService.selectForModel(modelNum);
        return Result.success(s);
    }
}
